package br.com.documentos.model.service;

import java.util.Calendar;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import br.com.documentos.model.entity.Documento;
import br.com.documentos.model.persistence.DocumentoRepository;

@Service
@Transactional(propagation=Propagation.REQUIRED, rollbackFor=Exception.class)
public class DocumentoService {

	@Autowired
	private DocumentoRepository documentoRepository;
	
	public void cadastrarDocumento( Documento documento ){
		
		documento.setDataCriacao(Calendar.getInstance());
		
		documentoRepository.save(documento);
	}
	
	public void atualizarDocumento( Documento documento ){
		documentoRepository.merge(documento);
	}
	
}
